﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Diagnostics;
using System.Threading;
using XBMC.Cache.Manager.Shared;

namespace XBMC.Cache.Manager
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            EventLogHelper.LogName = "XBMC Cache Manager";
            EventLogHelper.LogSource = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString();

#if (DEBUG)
            if (Debugger.IsAttached)
            {
                /*
                if (System.Environment.MachineName == "DSMITH")
                {
                    RegistryHelper.SaveRegistryOption("DBServer", "smithy.homeserver.com");
                    RegistryHelper.SaveRegistryOption("DBVideoDBName", "xbmc_video");
                    RegistryHelper.SaveRegistryOption("DBUsername", "xbmc");
                    RegistryHelper.SaveRegistryOption("DBPassword", "xbmc");
                    RegistryHelper.SaveRegistryOption("LocalCacheFolder", @"C:\Users\dsmith\Documents\Visual Studio 2010\Projects\XBMC Cache Manager\thumbnails");
                    RegistryHelper.SaveRegistryOption("CleanVideoDB", "False");
                    RegistryHelper.SaveRegistryOption("CleanMusicDB", "False");
                    RegistryHelper.SaveRegistryOption("CleanMusicCache", "False");
                }
                if (System.Environment.MachineName == "OFFICE")
                {
                    RegistryHelper.SaveRegistryOption("DBServer", "WHS");
                    RegistryHelper.SaveRegistryOption("DBVideoDBName", "xbmc_video");
                    RegistryHelper.SaveRegistryOption("DBUsername", "xbmc");
                    RegistryHelper.SaveRegistryOption("DBPassword", "xbmc");
                    RegistryHelper.SaveRegistryOption("LocalCacheFolder", @"\\WHS\xbmc\thumbnails");
                    RegistryHelper.SaveRegistryOption("CleanMusicDB", "False");
                    RegistryHelper.SaveRegistryOption("CleanMusicCache", "False");
                }
                */

                XBMCCacheManager service = new XBMCCacheManager();
                if (service.StartTimer())
                    Thread.Sleep(Timeout.Infinite);
            }
#else
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] { new XBMCCacheManager() };
            ServiceBase.Run(ServicesToRun);
#endif
        }

    }
}
